package com.example.agriapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.agriapp.data.SettingItem;
import com.example.agriapp.R;

import java.util.List;

public class SettingAdapter extends BaseAdapter {
    private Context context;
    private List<SettingItem> items;

    public SettingAdapter(Context context, List<SettingItem> items) {
        this.context = context;
        this.items = items;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public SettingItem getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.list_item_setting, parent, false);
        }

        SettingItem item = getItem(position);

        TextView titleView = convertView.findViewById(R.id.settingTitle);
        TextView statusView = convertView.findViewById(R.id.settingStatus);

        titleView.setText(item.getTitle());
        statusView.setText(item.getStatus());
        statusView.setVisibility(item.getStatus().isEmpty() ? View.GONE : View.VISIBLE);

        return convertView;
    }
}